//
//  XJIdentityChickView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/7/11.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJIdentityChickView.h"
#import "XJIdCheckCell.h"
#import "XJIdCheckModel.h"

@interface XJIdentityChickView()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tv;
@property (nonatomic, copy) NSArray *dataArray;

@property (nonatomic, strong) UILabel *chickIngLb;

@end

@implementation XJIdentityChickView

#pragma mark - 一 lazy
- (UITableView *)tv {
    if (!_tv) {
        _tv = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)];
        _tv.delegate  =self;
        _tv.dataSource = self;
        
        NSString *clsName = NSStringFromClass([XJIdCheckCell class]);
        
        [_tv registerNib:[UINib nibWithNibName:clsName bundle:nil] forCellReuseIdentifier:clsName];
        
        _tv.tableFooterView = [UIView new];
    }
    return _tv;
}

#pragma mark - 二 init
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView {
    
    self.tv.frame = self.bounds;
    [self addSubview:self.tv];
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KWidth, 300)];
    
    CGFloat k15 = 15.0;
    CGFloat kw = (KWidth - k15*2);
    
    //设置区头
    UIImageView *headerIv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tip_certified"]];
    headerIv.frame = CGRectMake(k15, 5, kw, 200);
    [headerView addSubview:headerIv];
    
    _chickIngLb = [[UILabel alloc] init];
    _chickIngLb.text = @"审核中";
    _chickIngLb.textAlignment = NSTextAlignmentCenter;
    _chickIngLb.frame = CGRectMake(k15, headerIv.rb_bottom + k15 , kw, 25);
    [headerView addSubview:_chickIngLb];
    
    self.tv.tableHeaderView =  headerView;
}

#pragma mark - 三 UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSString *clsName = NSStringFromClass([XJIdCheckCell class]);
    
    XJIdCheckCell *cell = [tableView dequeueReusableCellWithIdentifier:clsName];
    
    XJIdCheckModel *model = self.dataArray[indexPath.row];
    
    [cell configureXJIdCheckCellWithModel:model];
    return cell;
}


#pragma mark - 赋值

- (void)configureXJIdentityChickViewWithDataArray:(NSArray *)dataArray stateStr:(NSNumber *)state {
    _dataArray = dataArray;
    
    if ([state isEqualToNumber:@1]) {
        _chickIngLb.text = @"实名认证审核中";
    }else if([state isEqualToNumber:@2]) {
        _chickIngLb.text = @"已认证";
    }else {
        _chickIngLb.text = @"未认证";
    }
    
    [self.tv reloadData];
}

@end
